<?php
/**
 */
// from 0 local 1 from_mblog

define("CACHE_PREFIX_PUBU","_pubu_content");

class db_mblog_want_comment extends db_base {
    
	var $table_name = "mblog_want_comment";
	
	function db_mblog_want_comment()
	{
		parent::db_base();
	}
	
	

	function get_list_by_mid($mid,$p,$pcount)
	{
		$mid = intval($mid);
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$where = "mid = $mid and status = 1";
		$content = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc ",$where);
		return $content;
	}
	
	function get_count_by_mid($mid)
	{
		$mid = intval($mid);
		
		$where = "mid = $mid and status = 1";
		$content = $this->get_listcount($this->table_name,$where);
		return $content;
	}
	
	function insert_mblog_want_comment($mid,$uid,$nickname,$content,$head_url)
	{
		$ary["mid"] = $mid;
		$ary["create_uid"] = $uid;
		$ary["content"] = $content;
		$ary["status"] = 1;
		$ary["head_url"] = $head_url;
		$ary["create_nickname"] = $nickname;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		
		$res = $this->insert($this->table_name,$ary);
		
		if($res)
		{
			return $this->get_lastinsertid();
		}
		else
		{
			return false;
		}
	} 
	
	
	function update_by_id($id,$cid)
	{
		$id = intval($id);
		$where = "id = $id";
		$ary["cid"] = $cid;
		$res = $this->update($this->table_name,$ary,$where);
		return $res;
		
	}
	
	function cron_get_count_by_sina_id($sina_id)
	{
		$where = "cid = $sina_id";
		
		$count =$this->get_listcount($this->table_name,$where);
	
		return $count;
	}
	
	function cron_get_count_by_mid($mid)
	{
		$where = "mid = $mid and status = 1";
		
		$count =$this->get_listcount($this->table_name,$where);
	
		return $count;
	}

	

	function cron_insert_want_comment_info($uid,$user_nickname,$mid,$content,$sina_id,$head_url,$create_time)
	{
		// 插入数据
		$ary = array();

		
		$ary["create_nickname"] = $user_nickname;
		$ary["mid"] = $mid;
		$ary["content"] = $content;
		$ary["cid"] = $sina_id;
		$ary["create_uid"] = $uid;
		$ary["create_time"] = $create_time;
		$ary["create_ip"] = 0;
		$ary["status"] = 1;
		$ary["head_url"] = $head_url;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	

	
	
}



